Improve static asserts#642
Conversation
WalkthroughWalkthroughThe pull request introduces significant modifications across various files in the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
src/rpp/rpp/operators/combine_latest.hpp (1)
102-102: Approve the usage of the new utility to simplify the constraint.The change enhances the clarity and maintainability of the code by reducing complexity in the type constraints while ensuring that the functionality remains intact. The new utility
constraint::template_callable_or_invocableeffectively combines the previous checks into a single, more streamlined requirement.Consider adding a comment to explain the purpose of the new utility for better readability. For example:
requires (!rpp::constraint::observable<TSelector> && (constraint::template_callable_or_invocable<TSelector, rpp::utils::convertible_to_any, utils::extract_observable_type_t<TObservable>, utils::extract_observable_type_t<TObservables>...>)) // ^-- The new utility checks if TSelector is a callable or invocable with the specified types
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (21)
- src/rpp/rpp/disposables/fwd.hpp (1 hunks)
- src/rpp/rpp/operators/combine_latest.hpp (1 hunks)
- src/rpp/rpp/operators/distinct_until_changed.hpp (2 hunks)
- src/rpp/rpp/operators/filter.hpp (1 hunks)
- src/rpp/rpp/operators/flat_map.hpp (1 hunks)
- src/rpp/rpp/operators/fwd.hpp (8 hunks)
- src/rpp/rpp/operators/group_by.hpp (1 hunks)
- src/rpp/rpp/operators/map.hpp (1 hunks)
- src/rpp/rpp/operators/merge.hpp (1 hunks)
- src/rpp/rpp/operators/on_error_resume_next.hpp (1 hunks)
- src/rpp/rpp/operators/reduce.hpp (2 hunks)
- src/rpp/rpp/operators/retry_when.hpp (1 hunks)
- src/rpp/rpp/operators/scan.hpp (2 hunks)
- src/rpp/rpp/operators/subscribe.hpp (1 hunks)
- src/rpp/rpp/operators/take_while.hpp (1 hunks)
- src/rpp/rpp/operators/tap.hpp (3 hunks)
- src/rpp/rpp/operators/with_latest_from.hpp (1 hunks)
- src/rpp/rpp/operators/zip.hpp (1 hunks)
- src/rpp/rpp/sources/fwd.hpp (1 hunks)
- src/rpp/rpp/utils/constraints.hpp (0 hunks)
- src/rpp/rpp/utils/function_traits.hpp (1 hunks)
Files not reviewed due to no reviewable changes (1)
- src/rpp/rpp/utils/constraints.hpp
Additional comments not posted (41)
src/rpp/rpp/disposables/fwd.hpp (1)
14-14: LGTM!The addition of the include directive for
<rpp/utils/function_traits.hpp>is a valid change. It is likely to be used in the implementation files to enhance the capabilities of the code by leveraging type traits associated with functions.src/rpp/rpp/operators/flat_map.hpp (1)
69-69: Excellent addition ofstatic_assertfor improved type safety and clarity!The introduction of the
static_assertstatement enhances the type safety of theflat_mapfunction by explicitly checking the validity of the callable typeFn. This compile-time check ensures thatFn, if not a template callable, must return an observable type when invoked with a parameter of typerpp::utils::convertible_to_any.This change provides several benefits:
- It prevents potential misuse of the
flat_mapfunction with incompatible types, catching errors at compile-time rather than runtime.- It improves clarity and error messaging during compilation compared to the previous
requiresclause, making it easier for developers to understand and fix any issues.- It enhances the maintainability and robustness of the codebase by enforcing strict type requirements.
Great work on this improvement!
src/rpp/rpp/operators/filter.hpp (1)
96-96: Excellent addition ofstatic_assertfor improved type safety!The introduction of the
static_assertis a great enhancement to thefilterfunction. It enforces a clear and explicit constraint on thepredicateparameter, ensuring that it is either a template callable or invocable with a return type ofboolwhen applied torpp::utils::convertible_to_any.This compile-time check improves type safety by catching any incompatible
predicatetypes early in the development process. It provides clearer error messages during compilation, making it easier to identify and fix issues related to incorrectpredicatetypes.The use of
rpp::utils::convertible_to_anyallows flexibility in the types that can be passed to thepredicate, as long as they are convertible to the expected parameter type.Overall, this change enhances the robustness and maintainability of the code by preventing potential runtime errors and improving the developer experience.
src/rpp/rpp/operators/map.hpp (1)
99-99: Excellent addition ofstatic_assertto enforce callable constraints!The introduction of the
static_assertstatement with theconstraint::template_callable_or_invocable_ret_non_voidconcept effectively enforces the requirement for the callableFnto be either a template callable or an invocable function that returns a non-void type when called withrpp::utils::convertible_to_any.This change enhances type safety by catching any violations of the constraint at compile-time, preventing potential runtime errors related to void return types. The clear error message in the
static_assertstatement provides helpful feedback to developers if the constraint is not met, improving the maintainability and robustness of the code.Great work on improving the type safety and clarity of the
mapfunction!src/rpp/rpp/operators/take_while.hpp (1)
96-96: Excellent addition ofstatic_assertto enforce predicate constraints!The introduction of the
static_assertstatement enhances type safety by ensuring that the predicate functionFnadheres to the expected signature. This compile-time check prevents potential runtime errors related to incorrect function signatures and improves clarity regarding the expected behavior of the predicate.The constraint enforces that
Fnis either callable or invocable with a return type ofboolwhen applied torpp::utils::convertible_to_any, which is a meaningful and appropriate requirement for thetake_whileoperator.This change is a positive step towards improving the maintainability and robustness of the codebase.
src/rpp/rpp/utils/function_traits.hpp (10)
44-45: LGTM!The namespace closure is correct.
46-51: LGTM!The
is_not_template_callableconcept is correctly defined using theutils::is_not_template_callable_ttype trait.
52-53: LGTM!The
invocableconcept is correctly defined using thestd::invocableconcept.
55-56: LGTM!The
invocable_retconcept is correctly defined using theinvocableconcept and checking the return type usingstd::same_asandstd::invoke_result_t.
58-59: LGTM!The
template_callable_or_invocableconcept is correctly defined using theis_not_template_callableandinvocableconcepts.
61-62: LGTM!The
template_callable_or_invocable_ret_non_voidconcept is correctly defined using theis_not_template_callable,invocable, andinvocable_retconcepts to check if a function is not a template callable, invocable, and does not returnvoid.
64-65: LGTM!The
template_callable_or_invocable_retconcept is correctly defined using theis_not_template_callableandinvocable_retconcepts to check if a function is not a template callable, invocable, and returns the specifiedRettype.
67-68: LGTM!The
is_nothrow_invocableconcept is correctly defined using thestd::is_nothrow_invocable_vtype trait to check if a function is invocable without throwing an exception.
69-72: LGTM!The namespace closures and openings are correct.
75-75: LGTM!The
function_traitsstruct template is correctly modified to use theconstraint::is_not_template_callableconcept as a constraint for the template parameterT.src/rpp/rpp/sources/fwd.hpp (1)
39-39: LGTM!The change to use
constraint::is_not_template_callablefor theOnSubscribetemplate parameter is a good refactoring that improves code organization and clarity by moving the constraint to a more appropriate namespace.The default type for
Typeremains unchanged, maintaining the existing behavior of extracting the observer type from theOnSubscribecallable.Overall, the changes enhance the code without introducing any apparent issues or altering the core functionality of the
createfunction template.src/rpp/rpp/operators/distinct_until_changed.hpp (2)
58-58: Improved type safety and clarity in the static assertion.The change from
invocable_r_vtoinvocable_retenhances type safety by explicitly checking that the return type ofEqualityFnis a boolean when invoked with two parameters of typeT. This stricter check ensures that the function signature adheres to the expected return type.Additionally, the updated assertion message provides a clearer description of the expected function signature, improving the clarity of any compile-time errors related to this assertion.
102-102: New static assertion enhances type-checking and error messaging.The addition of the new static assertion using
template_callable_or_invocable_retprovides an additional layer of type-checking forEqualityFn. It ensures thatEqualityFnis either callable or invocable with the specified types (rpp::utils::convertible_to_any) and returns a boolean.This assertion reinforces the requirement that the function must return a boolean when invoked with the specified parameters, improving the robustness of the
distinct_until_changedoperator's implementation.Furthermore, the clear assertion message stating the expected function signature will help in identifying and resolving any compile-time errors related to this requirement, enhancing the developer experience.
src/rpp/rpp/operators/on_error_resume_next.hpp (1)
141-141: Excellent addition ofstatic_assertfor improved type safety and clarity!The introduction of the
static_assertstatement enhances the type safety and robustness of theon_error_resume_nextfunction by explicitly checking that the providedSelectoris invocable with astd::exception_ptrand returns an observable type.This change provides clearer compile-time error messages compared to the previous implementation, which only relied on a
requiresclause. It helps prevent misuse of the function and improves the maintainability of the codebase.src/rpp/rpp/operators/zip.hpp (1)
102-102: Improved constraint forTSelectortemplate parameter.The change to the constraint on the
TSelectortemplate parameter enhances code clarity and maintainability by consolidating the logic into a single, more descriptive constraint function,constraint::template_callable_or_invocable.The new constraint still ensures that
TSelectoris not an observable and is either a callable template or invocable with the specified types, maintaining the same functionality as the original constraint.src/rpp/rpp/operators/tap.hpp (3)
69-69: LGTM!The change from
invocable_r_vtoinvocable_retenhances the type safety by ensuring thatOnNextis not only invocable withTbut also returnsvoid. This aligns with the PR objective of improving static asserts and type safety.
93-93: Looks good!Moving the
is_not_template_callableconstraint from theutilsnamespace to theconstraintnamespace improves the organization and clarity of the codebase. The behavior of the code remains unchanged.
160-160: Looks good!As mentioned in the previous comment for line 93, moving the
is_not_template_callableconstraint from theutilsnamespace to theconstraintnamespace improves the organization and clarity of the codebase. The behavior of the code remains unchanged.src/rpp/rpp/operators/reduce.hpp (2)
Line range hint
134-148: Documentation update looks good!The parameter name change from
initial_valuetoseedin the documentation improves clarity and consistency with the variable name used in the code.
148-148: Great addition of thestatic_assert!The new
static_assertstatement enforces a compile-time check on the accumulator function, ensuring that it is callable with the seed type and returns the same type. This assertion enhances type safety and helps catch potential type mismatches at compile-time, improving the robustness of the code.src/rpp/rpp/operators/retry_when.hpp (1)
195-195: Improved error message clarity withstatic_assert.Replacing the
requiresclause with astatic_assertis a good change. It provides a more descriptive error message when theTNotifierconstraint is not met, improving the clarity of compilation errors for developers using this operator.src/rpp/rpp/operators/scan.hpp (1)
153-157: LGTM!The changes to the
scanfunction improve clarity and type safety without altering its behavior:
- Renaming the
initial_valueparameter toseedbetter reflects its purpose.- Updating the template type from
InitialValuetoSeedmaintains consistency with the new naming convention.- The updated static assertion ensures that the accumulator function is invocable with the new
Seedtype and the expected value type, enhancing type safety.Overall, these modifications enhance the readability and maintainability of the code.
src/rpp/rpp/operators/fwd.hpp (9)
30-31: LGTM!The introduction of
constraint::template_callable_or_invocableenhances the clarity and maintainability of the code by consolidating the checks for callable types and invocability. The change does not introduce any logical errors or alter the behavior of the function.
44-45: LGTM!The removal of the redundant check involving
utils::is_not_template_callablesimplifies the constraint and improves the readability of the code. The change does not introduce any logical errors or alter the behavior of the function.
52-53: LGTM!The removal of the redundant check involving
utils::is_not_template_callablesimplifies the constraint and improves the readability of the code. The change does not introduce any logical errors or alter the behavior of the function.
58-59: LGTM!The removal of the redundant check involving
utils::is_not_template_callablesimplifies the constraint and improves the readability of the code. The change does not introduce any logical errors or alter the behavior of the function.
60-62: LGTM!The removal of the redundant checks involving
utils::is_not_template_callablesimplifies the constraints and improves the readability of the code. The change does not introduce any logical errors or alter the behavior of the function.
Line range hint
84-85: LGTM!The removal of the redundant checks involving
utils::is_not_template_callablesimplifies the constraints and improves the readability of the code. The change does not introduce any logical errors or alter the behavior of the function.
100-101: LGTM!The change in parameter type from
InitialValuetoSeedstreamlines the function's interface and improves the clarity of the code. The change does not introduce any logical errors or alter the behavior of the function.
179-180: LGTM!The introduction of
constraint::template_callable_or_invocableenhances the clarity and maintainability of the code by consolidating the checks for callable types and invocability. The change does not introduce any logical errors or alter the behavior of the function.
192-193: LGTM!The introduction of
constraint::template_callable_or_invocableenhances the clarity and maintainability of the code by consolidating the checks for callable types and invocability. The change does not introduce any logical errors or alter the behavior of the function.src/rpp/rpp/operators/group_by.hpp (1)
220-222: LGTM!The
static_assertstatements are well-placed and improve the type safety of thegroup_byfunction. The error messages are clear and informative, which helps in identifying and fixing any constraint violations quickly.src/rpp/rpp/operators/merge.hpp (1)
258-258: Great addition of thestatic_assertto enforce type consistency at compile-time!The
static_assertusing theconstraint::observables_of_same_typeconstraint is a valuable addition as it ensures that all observables passed to themerge_withfunction are of the same type. This compile-time check will help catch any potential type mismatches early in the development process, improving the type safety and maintainability of the code.Note that this is a breaking change for any code that was previously passing observables of different types to
merge_with, but that would have been a bug anyway. The long-term benefits of the improved type safety outweigh the short-term inconvenience of fixing any such code.Overall, this is a great change that enhances the robustness of the
merge_withfunction. Well done!src/rpp/rpp/operators/with_latest_from.hpp (2)
201-201: Constraint refactoring improves code clarity.The change from the previous condition to the new
constraint::template_callable_or_invocableconstraint simplifies the code and improves readability without altering the behavior of the function.This refactoring enhances the maintainability of the codebase by consolidating the logic into a single, more expressive constraint.
Line range hint
230-233: No changes to review.This overload of
with_latest_fromhas no modifications in the provided code diff. Skipping review.src/rpp/rpp/operators/subscribe.hpp (1)
212-212: LGTM!The change to the
on_next_likeconcept simplifies the logic by consolidating the checks into a single concept usingrpp::constraint::template_callable_or_invocable<OnNext, rpp::utils::convertible_to_any>. This refinement potentially allows for broader compatibility with callable types while maintaining the necessary constraints.The exclusion of specific types remains intact, preserving the overall intent of the concept. This change improves the readability and maintainability of the concept.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
reduceandscanfunctions for better understanding.Refactor
Chores